package com.whfc.openapi.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xuguocheng
 * @desc 自定义WebMvcConfigurer
 * @date 2019-08-03
 */
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private OpenApiClientInterceptor openApiClientInterceptor;

    @Autowired
    private OpenApiHdcAuthInterceptor openApiHdcAuthInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 风潮业务拦截器
        registry.addInterceptor(openApiClientInterceptor)
                .addPathPatterns(
                        "/open/api/**",
                        "/open/api/faceGate/fcr/callback")
                .excludePathPatterns(
                        "/open/api/accessToken",
                        "/open/api/fvs/gb28181/**",
                        "/open/api/fvs/rtmp/**",
                        "/open/api/fvs/token/**",
                        "/open/api/faceGate/recCallBack",
                        "/open/api/faceGate/rec/**",
                        "/open/api/faceGate/yf/**",
                        "/open/api/faceGate/wo/**",
                        "/open/api/faceGate/wotu/**",
                        "/open/api/faceGate/wheat/**",
                        "/open/api/faceGate/hq/**",
                        "/open/api/rotary/**",
                        "/open/api/v1/auth/token",
                        "/open/api/v1/adsq/sync/**",
                        "/open/api/doc/file/upload/callback",
                        "/open/api/v1/car/hx/**",
                        "/open/api/v1/auth/checkUser",
                        "/open/api/v1/snms/**",
                        "/open/api/v1/wind/**",
                        "/open/api/v1/fsh/**",
                        "/open/api/v2/hdc/**",
                        "/open/api/v1/betv/**",
                        "/open/api/**/anon/**",
                        "/open/api/v1/env/dust/gas/**",
                        "/open/api/v1/uni/**");

        // 硬件中心认证拦截器
        registry.addInterceptor(openApiHdcAuthInterceptor)
                .addPathPatterns("/open/api/v1/fsh/**",
                        "/open/api/v2/hdc/**")
                .excludePathPatterns("/open/api/v1/fsh/login",
                        "/open/api/v2/hdc/alg/auth/token");
    }
}
